package com.cooper.dao.project;

import java.util.List;

import com.cooper.entity.ProjectEntity;
import com.cooper.pagination.PageInfo;
import com.cooper.vo.CompositeDesignerProjectVo;
import com.cooper.vo.ProjectVo;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.Insert;
import net.paoding.rose.jade.annotation.SQL;
@DAO
public interface ProjectDAO {
	@Insert(tableName="d_project_info")
	Long addProjectDo(ProjectEntity projectDo);
	
	@SQL("select * from  d_project_info where id=:1")
	ProjectEntity getProjectDo(Long id);
	
	@SQL("select * from  d_project_info where user_id=:1")
	ProjectEntity getProjectDoByUserId(Long userId);
	
	@SQL("select a.id,a.project_name,a.user_id,a.category,a.description,a.file_id from d_project_info a  where a.deleted='n' "
			+ " #if(null !=:1.userId && ''!=:1.userId){ and a.user_id=:1.userId} "
			+ " #if(null !=:1.category && ''!=:1.category){ and a.category=:1.category} "
			+ " #if(null !=:1.projectName && ''!=:1.projectName){ and a.project_name like CONCAT('%',:1.projectName,'%')} "
			+ " #if(null !=:2){ limit :2.startIndex,:2.pageSize} ")
	List<ProjectVo> queryProjects(ProjectVo queryParamVo, PageInfo pageInfo);
	
	@SQL("update d_project_info set modifier=:1.modifier,gmt_modified=:1.gmtModified,user_id=:1.userId,category=:1.category," +
			"file_id=:1.fileId,description=:1.description,project_name=:1.projectName"
			+ " where id=:1.id")
	void updateProject(ProjectEntity projectDo);
	
	@SQL("select count(1) from d_project_info a where a.deleted='n'"
			+ " #if(null !=:1.userId && ''!=:1.userId){ and a.user_id=:1.userId} "
			+ " #if(null !=:1.category && ''!=:1.category){ and a.category=:1.category} "
			+ " #if(null !=:1.projectName && ''!=:1.projectName){ and a.projectName like CONCAT('%',:1.projectName,'%')} "
			)
	int queryProjectsCount(ProjectVo queryVo);
	
	@SQL("select b.id as project_id,a.id as designer_id,a.store_name,a.seller_name,a.seller_file_id,a.favorite,a.user_id,a.email,a.tel,a.live_file_ids,b.category,b.description,b.file_id as project_file_id"
			+ ",c.id as address_id,concat(c.city_id,c.state_id,c.country_id,c.continent_id) as str_location_ids"
			+ ",concat(c.city_name,c.state_name,c.country_name,c.continent_name) as str_location_names,c.street "
			+ "from d_project_info b left join d_designer a on (a.user_id=b.user_id) left join d_address c on (a.id=c.outer_id) where a.deleted='n' and b.deleted='n' and c.deleted='n' "
			+ " #if(null !=:1.userId && ''!=:1.userId){ and a.user_id=:1.userId} "
			+ " order by a.gmt_modified desc"
			+ " #if(null !=:2){ limit :2.startIndex,:2.pageSize} ")
	List<CompositeDesignerProjectVo> queryProjects(CompositeDesignerProjectVo queryParamVo, PageInfo pageInfo);
	

	@SQL("select count(1) from d_project_info b left join d_designer a on (a.user_id=b.user_id) left join d_address c on (a.id=c.outer_id)  where a.deleted='n' and b.deleted='n' and c.deleted='n' "
			+ " #if(null !=:1.userId && ''!=:1.userId){ and a.user_id=:1.userId} "
		)
	int queryProjectsCount(CompositeDesignerProjectVo queryParamVo);
}
